package org.kabeja.parser.entities;

import org.kabeja.dxf.entity.DXFEntity;
import org.kabeja.dxf.entity.DXFText;
import org.kabeja.parser.DXFValue;

/**
 * @author shutao
 * @since 2022/4/25 11:55
 */
public class DXFTextHandler extends AbstractEntityHandler {
    public static final int TEXT_VALUE = 1;
    public static final int TEXT_HEIGHT = 40;
    public static final int TEXT_SCALEX = 41;
    public static final int TEXT_GENERATION_FLAG = 71;
    public static final int TEXT_ALIGN = 72;
    public static final int TEXT_VALIGN = 73;
    public static final int TEXT_ALIGN_X = 11;
    public static final int TEXT_ALIGN_Y = 21;
    public static final int TEXT_ALIGN_Z = 31;
    public static final int TEXT_STYLE = 7;
    public static final int TEXT_OBLIQUEANGLE = 51;
    public static final int TEXT_ROTATION = 50;
    protected DXFText text;
    protected String content;

    public DXFTextHandler() {
    }

    @Override
    public void endDXFEntity() {
        this.text.setText(this.content);
        this.content = "";
    }

    @Override
    public DXFEntity getDXFEntity() {
        return this.text;
    }

    @Override
    public String getDXFEntityName() {
        return "TEXT";
    }

    @Override
    public boolean isFollowSequence() {
        return false;
    }

    @Override
    public void parseGroup(int var1, DXFValue var2) {
        switch(var1) {
            case 1:
                this.content = var2.getValue();
                break;
            case 7:
                this.text.setTextStyle(var2.getValue());
                break;
            case 10:
                this.text.setX(var2.getDoubleValue());
                break;
            case 11:
                this.text.setAlignX(var2.getDoubleValue());
                this.text.setAlignmentPoint(true);
                break;
            case 20:
                this.text.setY(var2.getDoubleValue());
                break;
            case 21:
                this.text.setAlignY(var2.getDoubleValue());
                this.text.setAlignmentPoint(true);
                break;
            case 30:
                this.text.setZ(var2.getDoubleValue());
                break;
            case 31:
                this.text.setAlignZ(var2.getDoubleValue());
                this.text.setAlignmentPoint(true);
                break;
            case 40:
                this.text.setHeight(var2.getDoubleValue());
                break;
            case 41:
                this.text.setScaleX(var2.getDoubleValue());
                break;
            case 50:
                this.text.setRotation(var2.getDoubleValue());
                break;
            case 51:
                this.text.setObliqueAngle(var2.getDoubleValue());
                break;
            case 71:
                switch(var2.getIntegerValue()) {
                    case 2:
                        this.text.setBackward(true);
                        return;
                    case 4:
                        this.text.setUpsideDown(true);
                        return;
                    default:
                        return;
                }
            case 72:
                this.text.setAlign(var2.getIntegerValue());
                break;
            case 73:
                this.text.setValign(var2.getIntegerValue());
                break;
            default:
                super.parseCommonProperty(var1, var2, this.text);
        }

    }

    @Override
    public void parseObject(int var1, DXFValue var2, int type) {
        super.parseObjectProperty(var1, var2, type, this.text);
    }

    @Override
    public void startDXFEntity() {
        this.text = new DXFText();
        this.text.setDXFDocument(this.doc);
    }
}
